﻿using System;
using System.ComponentModel;

namespace Cloak
{
	/// <summary>
	/// Describes a proxy to a remote service which uses a generated client to make calls
	/// </summary>
	/// <typeparam name="TClient">The type of generated service client on which calls are made</typeparam>
	public interface IServiceProxy<TClient>
	{
		/// <summary>
		/// Executes an asynchronous call to a remote service using an instance of a generated client
		/// </summary>
		/// <typeparam name="TCompletedEventArgs">
		/// The type of generated arguments consumed by handlers for the call
		/// (use <see cref="System.ComponentModel.AsyncCompletedEventArgs"/> for methods which return void)
		/// </typeparam>
		/// <param name="subscribeToCompletedHandler">The action which subscribes an event handler to the generated completed event on the client instance</param>
		/// <param name="execute">The action which makes the call on the client instance</param>
		/// <param name="onCompleted">The action which handles the results of a successful call</param>
		/// <param name="onError">The action which handles the results of a failed call</param>
		/// <param name="onCancelled">The action which handles the results of a cancelled call</param>
		void ExecuteAsync<TCompletedEventArgs>(
			Action<TClient, EventHandler<TCompletedEventArgs>> subscribeToCompletedHandler,
			Action<TClient> execute,
			Action<TCompletedEventArgs> onCompleted = null,
			Action<Exception> onError = null,
			Action onCancelled = null)
			where TCompletedEventArgs : AsyncCompletedEventArgs;
	}
}